<?php
namespace heihei\web;
use Yii;

class RestSession extends \yii\web\CacheSession
{

    /**
     * @inheritdoc
     */
    public function init()
    {
        $loginToken = $this->getLoginToken();
        if($loginToken){
            parent::setId($loginToken);
            parent::setHasSessionId(true);
        }
        parent::init();
    }

    /**
     * 获取登录token
     */
    public function getLoginToken(){
        $name = $this->getName();
        return Yii::$app->getRequest()->getHeaders()->get($name);
    }
}
